cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        _curPage:null,
        _pages:null,
    },

    // use this for initialization
    onLoad: function () {

        cc.addClickEvent = function(node,target,component,handler){
            var eventHandler = new cc.Component.EventHandler();
            eventHandler.target = target;
            eventHandler.component = component;
            eventHandler.handler = handler;

            var clickEvents = node.getComponent(cc.Button).clickEvents;
            clickEvents.push(eventHandler);
        };
        
        cc.http = require("HTTP");
    
        this.node.addComponent("Menu");
        this.node.addComponent("UserInfo");
        this.node.addComponent("Alert");
        this.node.addComponent("PageLogin");
        this.node.addComponent("PageWJCK");
        this.node.addComponent("PageWDXX");
        
        this._pages = {};
        this._pages["login"] = cc.find("Canvas/page_login");
        this._pages["wjck"] = cc.find("Canvas/page_wjck");
        this._pages["hdgg"] = cc.find("Canvas/page_hdgg");
        this._pages["wdxx"] = cc.find("Canvas/page_wdxx");
        
        for(var k in this._pages){
            this._pages[k].active = false;
        }
        
        this.node.on("switch_page",function(data){
           var pageName = data.detail;
           this.switchPage(pageName);
        }.bind(this));
        
        cc.userdata = {};
        
        this.node.emit("switch_page","login");
    },
    
    switchPage:function(pageName){
        if(this._curPage != null){
            this._curPage.active = false;
        }
        this._curPage = this._pages[pageName];
        if(this._curPage){
            this._curPage.active = true;
        }
    }
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
